<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单管理')" />
</head>
<body class="gray-bg">
     <div class="container-div">
         <input type="hidden" id="supplierId" name="supplierId" th:value="${supplier.id}">
         <div class="col-sm-12 search-collapse">
             <form id="formId">
                 <div class="select-list">
                     <p>合计：总供煤数量： [[${totalAmount}]]   总待发煤数量： [[${notDeliverAmount}]]</p>
                     <ul>
                         <li>
                             <label>订单时间：</label>
                             <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="startTime"/>
                         </li>
                         <li>
                             <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
                         </li>
                         <li>
                             <label>订单状态：</label>
                             <select name="status">
                                 <option value="">所有</option>
                                 <option value="0">未付款</option>
<!--                                 <option value="1">已付款</option>-->
                                 <option value="2">未发货</option>
<!--                                 <option value="3">运输中</option>-->
                                 <option value="4">已收货</option>
                             </select>
                         </li>
                         <li>
                             <label>收货地址：</label>
                             <input type="text" name="address"/>
                         </li>
                         <li>
                             <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                             <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                         </li>
                     </ul>
                 </div>
             </form>
         </div>
        <div class="row">
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('jjm:order:edit')}]];
        var removeFlag = [[${@permission.hasPermi('jjm:order:remove')}]];
        var statusDatas = [[${@dict.getType('order_status')}]];
        var prefix = ctx + "jjm/order";

        $(function() {
            var options = {
                url: prefix + "/listBySupplier?supplierId="+[[${supplier.id}]],
                deliverUrl: prefix + "/deliver/{id}",
                modalName: "订单管理",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                columns: [
                    {
                        field: 'index',
                        title: '编号',
                        formatter: function(value, row, index) {
                            return $.table.serialNumber(index);
                        }
                    },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                    {
                        field: 'address',
                        title: '地址'
                    },
                {
                    field: 'createTime',
                    title: '订单时间',
                    formatter: function(value, row, index) {
                        return new Date(value).format("yyyy-MM-dd");
                    }
                },
                {
                    field: 'amount',
                    title: '购煤数量（吨）'
                },
                {
                    field: 'money',
                    title: '购煤款'
                },
                {
                    field: 'statusValue',
                    title: '订单状态'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status){
                            //发货
                            if(row.status <= 2){
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="deliver(\'' + row.id + '\')">发货</a> ');
                            }else if(row.status == 4){
                                actions.push(new Date(row.confirmTime).format("yyyy-MM-dd")+"收货");
                            }else{
                                actions.push(row.statusValue);
                            }
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function deliver(id) {
            table.set();
            $.modal.confirm("您确定要发货吗？", function() {
                var url = $.common.isEmpty(id) ? table.options.deliverUrl : table.options.deliverUrl.replace("{id}", id);
                if(table.options.type == table_type.bootstrapTreeTable) {
                    $.operate.get(url);
                } else {
                    var data = { "id": id };
                    $.operate.submit(url, "post", "json", data);
                }
            });

        }
    </script>
</body>
</html>